/*
 * @Author: wangming
 * @Date: 2020-09-03 16:33:37
 * @LastEditors: wangming
 * @LastEditTime: 2022-05-18 17:13:12
 * @Description: file content
 */
import myMixin from "@/pageComponents/myMixin";
import vmMixin from "@/pageComponents/vmMixin";
export default {
  vmEvents: {
    async select() {
      await this.$nextTick();
      this.$refs.input.select();
    },
    async blur() {
      await this.$nextTick();
      this.$refs.input.blur();
    },
    async focus() {
      await this.$nextTick();
      this.$refs.input.focus();
    },
  },
  mixins: [myMixin, vmMixin],
  methods: {
    async enter() {
      await this.$nextTick();
      this.runEventName("enter");
    },
  },
  async mounted() {
    if (this.config.__config.autofocus) {
      await this.$nextTick();
      this.$refs.input.focus();
    }
  },
  render(h) {
    const { placeholder, width, maxlength } = this.config.__config;
    if (this.viewInfo) {
      return (
        <div
          style={{
            display: "inline-block",
            whiteSpace: "break-spaces",
            width: width + "%",
          }}
        >
          {this.value}
        </div>
      );
    }
    return (
      <el-input
        ref="input"
        disabled={this.disabled}
        style={{
          width: width + "%",
        }}
        clearable
        value={this.value}
        placeholder={placeholder}
        maxlength={maxlength}
        onBlur={() => this.runEventName("blur")}
        onInput={(v) => {
          this.$emit("input", v);
          this.runEventName("change", { values: v });
        }}
        onFocus={() => this.runEventName("focus")}
        vOn:keyup_enter_native={this.enter}
        vOn:keyup_native={({ keyCode }) =>
          this.runEventName("keyup", { values: keyCode })
        }
      />
    );
  },
};
